/* 
 *  Syntelos XB
 *  Copyright (C) 2006 John Pritchard.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307 USA
 */

package syntelos.xb.op;

/**
 * <p> JVM instruction <code>0xb9 invokeinterface</code>. </p>
 */
public final class Invokeinterface
    extends syntelos.xb.Op.Constant
{
    public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ELEMENT_NODE,"http://www.syntelos.org/xb/op","xop:invokeinterface");

    public final static class Count
	extends syntelos.xb.Base.Attribute.Operand
    {
	public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ATTRIBUTE_NODE,"http://www.syntelos.org/xb/op","xop:invokeinterface.count");

	public Count(org.w3c.dom.Document doc, syntelos.iou.dom.Name type){
	    super(doc,type);
	}
	public Count(org.w3c.dom.Document doc){
	    this(doc,NAME);
	}
	public Count(){
	    this(DOC_NIL);
	}

	protected Invokeinterface getParentInvokeinterface(){
	    return (Invokeinterface)this.getParentNode();
	}
	public syntelos.xb.at.LocalVariableTable getAttributeLocalVariableTable(){
	    return this.getParentInvokeinterface().getAttributeLocalVariableTable();
	}
	public syntelos.xb.at.Code getAttributeCode(){
	    return this.getParentInvokeinterface().getAttributeCode();
	}
	public syntelos.xb.op.Code getOpCode(){
	    return this.getParentInvokeinterface().getOpCode();
	}
	public void readCF(syntelos.xb.IO.Uri src, syntelos.xb.CF.Reader reader)
	    throws java.io.IOException
	{
	    throw new syntelos.xb.Error.Bug();	// Driven by Invokeinterface
	}
	public void writeCF(syntelos.xb.IO.Uri dst, syntelos.xb.CF.Writer writer)
	    throws java.io.IOException
	{
	    throw new syntelos.xb.Error.Bug();	// Driven by Invokeinterface
	}
    }

    public final static int code = CODE_INVOKEINTERFACE;
    public final static java.lang.String name = "invokeinterface";
    public final static int size_operands = 4;
    public final static int count_stack_pop = 2;
    public final static int count_stack_push = 0;


    public Invokeinterface(org.w3c.dom.Document doc, syntelos.iou.dom.Name type){
        super(doc,type);
    }
    public Invokeinterface(){
        super(NAME,false);
    }
    public Invokeinterface(boolean shared){
        super(NAME,true);
    }

    public Count getOperandCountAttr(){
	return (Count)this.getCreateAttributeNode(Count.NAME);
    }
    public int getOperandCount(){
	Count count = this.getOperandCountAttr();
	return count.getOperand();
    }
    public void setOperandCount(int value){
	Count count = this.getOperandCountAttr();
	count.setOperand(value);
    }
    public int getCode(){
        return code;
    }
    public java.lang.String getName(){
        return name;
    }
    public int sizeOperands(){
        return size_operands;
    }
    public int countStackPop(){
        return count_stack_pop;
    }
    public int countStackPush(){
        return count_stack_push;
    }
    public void readCF(syntelos.xb.Class clas, syntelos.xb.Method meth, syntelos.xb.Op.Reader in)
        throws java.io.IOException
    {
        if (this.setPC(in)){
            if (0 < size_operands){
                byte[] cf = new byte[size_operands];
                in.readFully(cf,0,size_operands);
                this.setCF(cf);
		this.setOperand(this.getCFIntU2(0));
		this.setOperandCount(this.getCFIntU1(2));
            }
        }
        else
            throw new syntelos.xb.Error.Bug();
    }
    public void writeCF(syntelos.xb.Class clas, syntelos.xb.Method meth, syntelos.xb.Op.Writer out)
        throws java.io.IOException
    {
        if (this.setPC(out)){
            byte[] cf = this.getCF();
	    this.setCFIntU2(0,this.getOperand());
	    this.setCFIntU1(2,this.getOperandCount());
	    out.write(cf);
        }
        else
            throw new syntelos.xb.Error.Bug();
    }
}
